<?php

namespace App\Jobs;


use App\Libraries\Easemob\Easemob;
use App\Libraries\Tools\Msg;
use App\Models\HongBao\HongBao;
use App\Models\Msg\MsgSystem;
use Illuminate\Support\Facades\Log;
use JMessage\IM\Message;
use JMessage\JMessage;

class SendPraiseMsgJob extends Job
{


    private $user_id;
    private $text;


    public function __construct($user_id, $text)
    {
        $this->user_id = $user_id;
        $this->text = $text;
    }

    /**
     * Execute the job.
     * @return bool
     * @throws \Exception
     */
    public function handle()
    {

//        Easemob::singleton()->addFriend(8, $this->user_id);
//        $data = Easemob::singleton()->sendText(8, 'users', [$this->user_id], $this->text, ['user_id'=>8, 'type'=>0]);
//        if(!empty($data['error'])){
//            throw new \Exception('send normal msg Fail');
//        }
        $client = new JMessage(env('JMSG_APPKEY'), env('JMSG_SECRET'));
        $message = new Message($client);
        $message->sendText(1, [
            'type' => 'admin',
            'id'   => 'beboy_5',
            'name' => '赞'
        ], [
            'type' => 'single',
            'id'   => 'beboy_'.$this->user_id,
        ], [
            'text' => $this->text,
            'extras' => ['user_id'=>5, 'type'=>0]
        ], [
            'notifiable' => false
        ], [
            'offline' => true
        ]);
        return true;
    }
}
